//
//  ProductCreateVC.m
//  danpin
//
//  Created by chuangjia on 23/7/15.
//  Copyright (c) 2015 chuangjia. All rights reserved.
//

#import "ProductCreateVC.h"
#import "CategarySelectVC.h"
#import "BrandSelectVC.h"
#import "ZToastManager.h"
#import "UIPlaceholderTextView.h"
#import "BaseModel.h"
#import "GoodViewController.h"
@interface ProductCreateVC ()<UITableViewDataSource,UITableViewDelegate,UIActionSheetDelegate,UITextFieldDelegate,UITextViewDelegate>
{
    
}
@property(nonatomic,strong)UITableView *tbView;
@property(nonatomic,strong) UITextField     *txtPrice;
@property(nonatomic,strong) UITextField     *txtTitle;
@property(nonatomic,strong)UIPlaceholderTextView *mTextView;

@property(nonatomic,strong)NSMutableArray *setcionArray;
@property(nonatomic,strong)NSMutableArray *pictureArray;
@property(nonatomic,strong)NSMutableArray *ImageArray;
@property(nonatomic,strong)NSMutableArray *TextArray;
@property(nonatomic,assign)BOOL isCategoryEnable;
@property(nonatomic,strong) NSString *cateId;
@property(nonatomic,strong) NSString *cateString;
@property(nonatomic,strong) NSDictionary *cateDictionary;

@property(nonatomic,strong) NSString *brandId;
@property(nonatomic,strong) NSString *brandString;
@property(nonatomic,strong) NSString *cnameId;
@property(nonatomic,strong) NSString *cnameString;
@property(nonatomic,strong) NSString *soldTitle;
@property(nonatomic,strong) NSString *priceString;
@property(nonatomic,strong) NSString *priceType;

@end

@implementation ProductCreateVC
@synthesize type=_type;
@synthesize dictionary=_dictionary;
@synthesize top=_top;
@synthesize pictureinfolist=_pictureinfolist;
@synthesize rank_id=_rank_id;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view
    
    self.view.backgroundColor =[UIColor whiteColor];
    self.rightTitle =@"发布";
    self.navTitle =@"单品信息";
    //
    _isCategoryEnable =NO;
    _cateId =@"";
    _cateString =@"";
    _brandId =@"";
    _brandString = [NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"brand_name"]];
    _cnameId =@"";
    _cnameString=@"";
    _soldTitle =[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"sold_title"]];
    _priceString=[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"price"]];
    _priceType=[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"currency"]];
    //
    if (!_setcionArray) {
        _setcionArray =[[NSMutableArray alloc] init];
    }
     _setcionArray =[NSMutableArray arrayWithObjects:@"品名:",@"原名:",@"描述:",@"分类:",@"品牌:",@"价格:",@"币种:", nil];
    //
    
    if (!_pictureArray) {
        _pictureArray =[[NSMutableArray alloc] init];
    }
    if (!_ImageArray) {
        _ImageArray =[[NSMutableArray alloc] init];
    }
    [_ImageArray removeAllObjects];
    
   
    if (!_TextArray) {
        _TextArray =[[NSMutableArray alloc] init];
    }
    [_TextArray removeAllObjects];
    
    //
    [self initUI];
    
}
-(void)clickNavEvent:(id)sender
{
    UIButton *btn =(UIButton*)sender;
    switch (btn.tag) {
        case 0:
        {
            self.navigationController.enableBackGesture=YES;
            if (self.navigationController) {
                if (self.navigationController.viewControllers.count == 1) {
                    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
                } else {
                    [self.navigationController popViewControllerAnimated:YES];
                }
            } else {
                [self dismissViewControllerAnimated:YES completion:nil];
            }
        }
            break;
        case 1:
        {
            [self okAction];
        }
            break;
        default:
            break;
    }
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
      DLog(@"%s", __PRETTY_FUNCTION__);
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [_setcionArray removeAllObjects];
    _setcionArray=nil;
    [_pictureArray removeAllObjects];
    _pictureArray=nil;
    [_ImageArray removeAllObjects];
    _ImageArray=nil;
    [_TextArray removeAllObjects];
    _TextArray=nil;
    DLog(@"%s", __PRETTY_FUNCTION__);
}
-(UIView *)footerView
{
    //
    NSString *txt =@"发布商品请注意以下规则:\n\n1，不能发布色情、暴力、反动等违反国家法规的商品信息。严重违纪者，单品APP将直接移送司法机关。\n\n2，不允许在品牌、品名、商品描述内添加广告信息，一经发现，单品APP将删除商品，并封停发布者的帐号。\n\n3，所有商品进入商品库，会经过编辑审核，如果您希望顺利通过审核，请保证商品图片干净：没有商家广告信息及各种水印。商品品名间接：型号+功能+物品名 为格式。产品描述准确到位，字数不宜过多。\n\n4，为了消费者能够更好的了解商品，单品的编辑可能会更新商品图片和文字信息。";
    
    NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:txt];
    
    // 设置富文本基本属性
    [attrStr setFont:FONT(13)];
    [attrStr setTextColor:UIColorFromRGB(0x808080)];
    
    OHParagraphStyle* paragraphStyle = [OHParagraphStyle defaultParagraphStyle];
    paragraphStyle.textAlignment = kCTTextAlignmentLeft;
    paragraphStyle.lineBreakMode = kCTLineBreakByWordWrapping;
    paragraphStyle.firstLineHeadIndent = 0.f; // indentation for first line
    paragraphStyle.lineSpacing = 5.f; // increase space between lines by 3 points
    [attrStr setParagraphStyle:paragraphStyle];
    
    CGSize sz = [attrStr sizeConstrainedToSize:CGSizeMake(DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4, CGFLOAT_MAX)];
    CGFloat h =sz.height+30;
    NSString*url =[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"sold_url"]];
    if (url.length>0 && ![url isEqualToString:@"(null)"]) {
        h =h+DEVICE_HEIGHT-self.navHeight+21;
    }
    UIView *footer =[[UIView alloc] initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH, h)];
    footer.backgroundColor=[UIColor clearColor];
    UIView *line =[[UIView alloc] initWithFrame:CGRectMake(0, 10, DEVICE_WIDTH,0.5)];
    line.backgroundColor = UIColorFromRGB(0xcccccc);
    [footer addSubview:line];
    line=nil;
    //
    if (url.length>0 && ![url isEqualToString:@"(null)"]) {
        UIWebView *webView =[[UIWebView alloc] initWithFrame:CGRectMake(0, 20, DEVICE_WIDTH,DEVICE_HEIGHT-self.navHeight)];
        NSURL *url1 =[NSURL URLWithString:url];
        NSURLRequest *request =[NSURLRequest requestWithURL:url1];
        [webView loadRequest:request];
        [footer addSubview:webView];
        webView=nil;
    }
    
    //
    UIView *line1 =[[UIView alloc] initWithFrame:CGRectMake(0, DEVICE_HEIGHT-self.navHeight +25, DEVICE_WIDTH,0.5)];
    line1.backgroundColor = UIColorFromRGB(0xcccccc);
    [footer addSubview:line1];
    line1=nil;
    
    OHAttributedLabel* Infolabel = [[OHAttributedLabel alloc]initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH*2, DEVICE_HEIGHT-self.navHeight+30, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4,sz.height)];
    Infolabel.attributedText =attrStr;
    [footer addSubview:Infolabel];
    Infolabel=nil;
    
    
    return footer;
}
//
-(void)initUI
{
    _tbView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.navHeight, self.view.bounds.size.width, self.view.bounds.size.height-self.navHeight) style:UITableViewStyleGrouped];
    _tbView.delegate = self;
    _tbView.dataSource = self;
    _tbView.backgroundColor =[UIColor whiteColor];
    _tbView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tbView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.tbView.tableFooterView = [self footerView];
    [self.view addSubview:_tbView];
}
#pragma mark - tableview
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.setcionArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row==1) {
        NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:_soldTitle];
        // 设置富文本基本属性
        [attrStr setFont:FONT(13)];
        [attrStr setTextColor:UIColorFromRGB(0x808080)];
        
        OHParagraphStyle* paragraphStyle = [OHParagraphStyle defaultParagraphStyle];
        paragraphStyle.textAlignment = kCTTextAlignmentLeft;
        paragraphStyle.lineBreakMode = kCTLineBreakByWordWrapping;
        paragraphStyle.firstLineHeadIndent = 0.f; // indentation for first line
        paragraphStyle.lineSpacing = 5.f; // increase space between lines by 3 points
        [attrStr setParagraphStyle:paragraphStyle];
        
        CGSize sz = [attrStr sizeConstrainedToSize:CGSizeMake(DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4-50, CGFLOAT_MAX)];
        
        if (sz.height>50) {
            return sz.height+PHOTO_TIME_PADDING;
        }
        return 50;
    }else
    if(indexPath.row==2)
    {
        return 100;
    }
    return 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = (UITableViewCell*)[tableView  dequeueReusableCellWithIdentifier:@""];
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
        cell.backgroundColor=[UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    NSString *title =[self.setcionArray objectAtIndex:indexPath.row];
    switch (indexPath.row) {
        case 3:
        {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            UIView *cellView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, cell.frame.size.height)];
            cellView.backgroundColor = [UIColor clearColor];
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH*2, 0, 50, cell.frame.size.height)];
            [titleLabel setBackgroundColor:[UIColor clearColor]];
            [titleLabel setTextAlignment:NSTextAlignmentCenter];
            [titleLabel setFont:FONT(14)];
            [titleLabel setTextColor:[UIColor darkGrayColor]];
            titleLabel.text = title;
            [cellView addSubview:titleLabel];
            titleLabel=nil;
            UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(50+PHOTO_FRAME_WIDTH*2, 0,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4-50, cell.frame.size.height)];
            [contentLabel setBackgroundColor:[UIColor clearColor]];
            [contentLabel setTextAlignment:NSTextAlignmentLeft];
            [contentLabel setFont:FONT(13)];
            [contentLabel setTextColor:[UIColor lightGrayColor]];
            if (_cateString.length>0) {
                contentLabel.text = [NSString stringWithFormat:@"%@",_cateString];
            }else{
                contentLabel.text = [NSString stringWithFormat:@"%@",@"可选"];
            }
            [cellView addSubview:contentLabel];
            contentLabel=nil;
            UIView *lineView =[[UIView alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH*2, cell.frame.size.height-0.5,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4, 0.5)];
            lineView.backgroundColor =UIColorFromRGB(0xf4f4f4);
            [cellView addSubview:lineView];
            lineView=nil;
            
            [cell addSubview:cellView];
            return cell;
        }
            break;
        case 4:
        {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            UIView *cellView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, cell.frame.size.height)];
            cellView.backgroundColor = [UIColor clearColor];
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH*2, 0, 50, cell.frame.size.height)];
            [titleLabel setBackgroundColor:[UIColor clearColor]];
            [titleLabel setTextAlignment:NSTextAlignmentCenter];
            [titleLabel setFont:FONT(14)];
            [titleLabel setTextColor:[UIColor darkGrayColor]];
            titleLabel.text = title;
            [cellView addSubview:titleLabel];
            titleLabel=nil;
            UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(50+PHOTO_FRAME_WIDTH*2, 0,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4-50, cell.frame.size.height)];
            [contentLabel setBackgroundColor:[UIColor clearColor]];
            [contentLabel setTextAlignment:NSTextAlignmentLeft];
            [contentLabel setFont:FONT(13)];
            [contentLabel setTextColor:[UIColor lightGrayColor]];
            if (_brandString.length>0) {
                contentLabel.text = [NSString stringWithFormat:@"%@",_brandString];
            }else{
                contentLabel.text = [NSString stringWithFormat:@"%@",@"可选"];
            }
            [cellView addSubview:contentLabel];
            contentLabel=nil;
            UIView *lineView =[[UIView alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH*2, cell.frame.size.height-0.5,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4, 0.5)];
            lineView.backgroundColor =UIColorFromRGB(0xf4f4f4);
            [cellView addSubview:lineView];
            lineView=nil;
            [cell addSubview:cellView];
            return cell;
        }
            break;
        case 1:
        {
            UIView *cellView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, [self tableView:tableView heightForRowAtIndexPath:indexPath])];
            cellView.backgroundColor = [UIColor clearColor];
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH*2, PHOTO_TIME_PADDING/2, 50, 25)];
            [titleLabel setBackgroundColor:[UIColor clearColor]];
            [titleLabel setTextAlignment:NSTextAlignmentCenter];
            [titleLabel setFont:FONT(14)];
            [titleLabel setTextColor:[UIColor darkGrayColor]];
            titleLabel.text = title;
            [cellView addSubview:titleLabel];
            titleLabel=nil;
            NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:_soldTitle];
            // 设置富文本基本属性
            [attrStr setFont:FONT(13)];
            [attrStr setTextColor:UIColorFromRGB(0x808080)];
            
            OHParagraphStyle* paragraphStyle = [OHParagraphStyle defaultParagraphStyle];
            paragraphStyle.textAlignment = kCTTextAlignmentLeft;
            paragraphStyle.lineBreakMode = kCTLineBreakByWordWrapping;
            paragraphStyle.firstLineHeadIndent = 0.f; // indentation for first line
            paragraphStyle.lineSpacing = 5.f; // increase space between lines by 3 points
            [attrStr setParagraphStyle:paragraphStyle];
            
            CGSize sz = [attrStr sizeConstrainedToSize:CGSizeMake(DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4-50, CGFLOAT_MAX)];

            UITextView *textview = [[UITextView alloc] initWithFrame:CGRectMake(50+PHOTO_FRAME_WIDTH*2, 0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4-50,sz.height+PHOTO_FRAME_WIDTH)];
            textview.backgroundColor=[UIColor clearColor]; //背景色
            textview.scrollEnabled = NO;    //当文字超过视图的边框时是否允许滑动，默认为“YES”
            textview.editable = NO;        //是否允许编辑内容，默认为“YES”
            [textview setFont:FONT(13)];
            [textview setTextColor:UIColorFromRGB(0x808080)];
            textview.textAlignment = NSTextAlignmentLeft; //文本显示的位置默认为居左
            textview.text=_soldTitle;
            NSMutableParagraphStyle *paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
            paragraphStyle1.lineSpacing = 3;// 字体的行间距
            paragraphStyle1.alignment = NSTextAlignmentLeft;
            paragraphStyle1.lineBreakMode = kCTLineBreakByWordWrapping;
            paragraphStyle1.firstLineHeadIndent = 0.f; // indentation for first line
        
            NSDictionary *attributes = @{
                                         NSFontAttributeName:[UIFont systemFontOfSize:13],
                                         NSForegroundColorAttributeName:UIColorFromRGB(0x808080),
                                         NSParagraphStyleAttributeName:paragraphStyle1
                                         };
            NSAttributedString *tt =[[NSAttributedString alloc] initWithString:_soldTitle attributes:attributes];
            textview.attributedText =tt;
            [cellView addSubview:textview];
            tt=nil;
            textview=nil;
            UIView *lineView =[[UIView alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH*2, cellView.frame.size.height-0.5,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4, 0.5)];
            lineView.backgroundColor =UIColorFromRGB(0xf4f4f4);
            [cellView addSubview:lineView];
            lineView=nil;
            [cell addSubview:cellView];
            return cell;
        }
            break;
        case 0:
        {
            UIView *cellView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, cell.frame.size.height)];
            cellView.backgroundColor = [UIColor clearColor];
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH*2, 0, 50, cell.frame.size.height)];
            [titleLabel setBackgroundColor:[UIColor clearColor]];
            [titleLabel setTextAlignment:NSTextAlignmentCenter];
            [titleLabel setFont:FONT(14)];
            [titleLabel setTextColor:[UIColor darkGrayColor]];
            titleLabel.text = title;
            [cellView addSubview:titleLabel];
            titleLabel=nil;
            self.txtTitle.frame =CGRectMake(50+PHOTO_FRAME_WIDTH*2, 1, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4-50, cell.frame.size.height);
            [cellView addSubview:self.txtTitle];

            UIView *lineView =[[UIView alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH*2, cell.frame.size.height-0.5,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4, 0.5)];
            lineView.backgroundColor =UIColorFromRGB(0xf4f4f4);
            [cellView addSubview:lineView];
            lineView=nil;
            [cell addSubview:cellView];
            return cell;
        }
            break;
        case 2:
        {
            UIView *cellView =[[UIView alloc] initWithFrame:CGRectMake(0, PHOTO_FRAME_WIDTH, tableView.frame.size.width, 80)];
            cellView.backgroundColor = [UIColor clearColor];
        
            self.mTextView.frame =CGRectMake(PHOTO_FRAME_WIDTH*2, 0, tableView.frame.size.width-PHOTO_FRAME_WIDTH*4, 80);
            [cellView addSubview:self.mTextView];
            [cell addSubview:cellView];
            return cell;
        }
            break;
        case 5:
        {
            UIView *cellView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, cell.frame.size.height)];
            cellView.backgroundColor = [UIColor clearColor];
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH*2, 0, 50, cell.frame.size.height)];
            [titleLabel setBackgroundColor:[UIColor clearColor]];
            [titleLabel setTextAlignment:NSTextAlignmentCenter];
            [titleLabel setFont:FONT(14)];
            [titleLabel setTextColor:[UIColor darkGrayColor]];
            titleLabel.text = title;
            [cellView addSubview:titleLabel];
            titleLabel=nil;
            self.txtPrice.frame =CGRectMake(50+PHOTO_FRAME_WIDTH*2, 1, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4-50, cell.frame.size.height);
            if (_priceString.length>0) {
                self.txtPrice.text =_priceString;
            }
            [cellView addSubview:self.txtPrice];
            
            UIView *lineView =[[UIView alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH*2, cell.frame.size.height-0.5,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4, 0.5)];
            lineView.backgroundColor =UIColorFromRGB(0xf4f4f4);
            [cellView addSubview:lineView];
            lineView=nil;
            [cell addSubview:cellView];
            return cell;
        }
            break;
        case 6:
        {
            UIView *cellView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, cell.frame.size.height)];
            cellView.backgroundColor = [UIColor clearColor];
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH*2, 0, 50, cell.frame.size.height)];
            [titleLabel setBackgroundColor:[UIColor clearColor]];
            [titleLabel setTextAlignment:NSTextAlignmentCenter];
            [titleLabel setFont:FONT(14)];
            [titleLabel setTextColor:[UIColor darkGrayColor]];
            titleLabel.text = title;
            [cellView addSubview:titleLabel];
            titleLabel=nil;
            UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(50+PHOTO_FRAME_WIDTH*2, 0,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4-50, cell.frame.size.height)];
            [contentLabel setBackgroundColor:[UIColor clearColor]];
            [contentLabel setTextAlignment:NSTextAlignmentLeft];
            [contentLabel setFont:FONT(13)];
            [contentLabel setTextColor:[UIColor darkGrayColor]];
            if (_priceType.length>0) {
                contentLabel.text = [NSString stringWithFormat:@"%@",_priceType];
            }else{
                contentLabel.text = [NSString stringWithFormat:@"%@",@"人民币"];
            }
            [cellView addSubview:contentLabel];
            contentLabel=nil;
            [cell addSubview:cellView];
            return cell;
        }
            break;
        default:
            break;
    }
    return cell;
}
-(UITextField *)txtPrice
{
    if (!_txtPrice) {
        self.txtPrice = [[UITextField alloc] initWithFrame:CGRectZero];
        self.txtPrice.textColor =[UIColor lightGrayColor];
        [self.txtPrice setBorderStyle:UITextBorderStyleNone];
        self.txtPrice.clearButtonMode = UITextFieldViewModeWhileEditing;
        self.txtPrice.font = FONT(13);
        self.txtPrice.placeholder =@"选填";
        self.txtPrice.autocorrectionType = UITextAutocorrectionTypeNo;
        self.txtPrice.autocapitalizationType = UITextAutocapitalizationTypeNone;
        self.txtPrice.returnKeyType = UIReturnKeyDone;
        self.txtPrice.keyboardType =UIKeyboardTypeNumbersAndPunctuation;
        self.txtPrice.delegate=self;
        [self.txtPrice setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
        [self.txtPrice setValue:FONT(13) forKeyPath:@"_placeholderLabel.font"];
    }
    return _txtPrice;
}
-(UITextField *)txtTitle
{
    if (!_txtTitle) {
        self.txtTitle = [[UITextField alloc] initWithFrame:CGRectZero];
        self.txtTitle.textColor =[UIColor lightGrayColor];
        [self.txtTitle setBorderStyle:UITextBorderStyleNone];
        self.txtTitle.clearButtonMode = UITextFieldViewModeWhileEditing;
        self.txtTitle.font = FONT(13);
        self.txtTitle.placeholder =@"必填";
        self.txtTitle.autocorrectionType = UITextAutocorrectionTypeNo;
        self.txtTitle.autocapitalizationType = UITextAutocapitalizationTypeNone;
        self.txtTitle.returnKeyType = UIReturnKeyDone;
        self.txtTitle.delegate=self;
        [self.txtTitle setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
        [self.txtTitle setValue:FONT(13) forKeyPath:@"_placeholderLabel.font"];
    }
    return _txtTitle;
}
-(UIPlaceholderTextView*)mTextView
{
    if (!_mTextView) {
        self.mTextView =[[UIPlaceholderTextView alloc]initWithFrame:CGRectZero];
        self.mTextView.backgroundColor =[UIColor clearColor];
        self.mTextView.layer.borderColor =UIColorFromRGB(0xcccccc).CGColor;
        self.mTextView.layer.borderWidth =0.5;
        self.mTextView.layer.cornerRadius=3;
        self.mTextView.textColor = [UIColor darkGrayColor];
        self.mTextView.font =FONT(14);
        self.mTextView.delegate=self;
        self.mTextView.placeholder=@"单品描述...";
        self.mTextView.returnKeyType = UIReturnKeyDone;
    }
    return _mTextView;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    [self.mTextView resignFirstResponder];
    return YES;
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.txtPrice resignFirstResponder];
    [self.txtTitle resignFirstResponder];
    [self.mTextView resignFirstResponder];
    if (indexPath.section==0) {
        switch (indexPath.row) {
            case 3:
            {
                CategarySelectVC *cs =[[CategarySelectVC alloc] init];
                [cs setSelectedCallBack:^(id date , id key) {
                    if (date && [date isKindOfClass:[NSDictionary class]]) {
                        _cateDictionary = date;
                        _isCategoryEnable =YES;
                        _cateId =[NSString stringWithFormat:@"%@",[date objectForKey:@"cate_id"]];
                        _cateString =[NSString stringWithFormat:@"%@",[date objectForKey:@"cate_name"]];
                        [_tbView reloadData];
                    }
                    
                }];
                [self.navigationController pushViewController:cs animated:YES];
            }
                break;
            case 4:
            {
                
                    BrandSelectVC *cs =[[BrandSelectVC alloc] init];
                    cs.cate_id =_cateId;
                    [cs setSelectedCallBack:^(id date , id key) {
                        if (date && [date isKindOfClass:[NSDictionary class]]) {
                            _brandId =[NSString stringWithFormat:@"%@",[date objectForKey:@"brand_id"]];
                            _brandString =[NSString stringWithFormat:@"%@",[date objectForKey:@"brand_name"]];
                            [_tbView reloadData];
                        }
                        
                    }];
                    [self.navigationController pushViewController:cs animated:YES];
               
                
            }
                break;
           
            default:
                break;
        }
    }
}
-(void)okAction
{

    if (self.txtTitle.text.length==0) {
        [[ZToastManager ShardInstance] showtoast:@"请填写单品名称"];
        return;
    }
    if (self.txtPrice.text.length==0) {
        [[ZToastManager ShardInstance] showtoast:@"请填写单品价格"];
        return;
    }
    if (self.mTextView.text.length==0) {
        [[ZToastManager ShardInstance] showtoast:@"请介绍下单品"];
        return;
    }
    NSMutableDictionary *dict =[NSMutableDictionary dictionary];
    [dict setValue:[NSString stringWithFormat:@"%@",[self.cateDictionary objectForKey:@"cate_id"]] forKey:@"cate_id"];
    [dict setValue:[NSString stringWithFormat:@"%@",[self.cateDictionary objectForKey:@"cate_name"]] forKey:@"cate_name"];
    [dict setValue:[NSString stringWithFormat:@"%@",[self.cateDictionary objectForKey:@"group_id"]] forKey:@"group_id"];
    [dict setValue:[NSString stringWithFormat:@"%@",[self.cateDictionary objectForKey:@"group_name"]] forKey:@"group_name"];
    if (_brandId.length==0 || [_brandId isEqualToString:@"(null)"]) {
        _brandId = [NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"brand_id"]];
    }
    [dict setValue:_brandId forKey:@"brand_id"];
    
    if (_brandString.length==0|| [_brandString isEqualToString:@"(null)"]) {
        _brandString = [NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"brand_name"]];
    }
    [dict setValue:_brandString forKey:@"brand_name"];
    
    
  
    [dict setValue:self.txtTitle.text forKey:@"title"];
    [dict setValue:self.mTextView.text forKey:@"picture_text"];
    [dict setValue:self.txtPrice.text forKey:@"price"];
    if(_priceType.length==0||[_priceType isEqualToString:@"(null)"])
    {
        _priceType=@"人民币";
    }
    [dict setValue:self.priceType forKey:@"currency"];
    
    [dict setValue:[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"model_name"]] forKey:@"model_name"];
    [dict setValue:[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"total_sold"]] forKey:@"total_sold"];
    [dict setValue:[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"sold_url"]] forKey:@"sold_url"];
    [dict setValue:[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"from_site"]] forKey:@"from_site"];
    [dict setValue:[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"itemid"]] forKey:@"itemid"];
    [dict setValue:[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"sold_url"]] forKey:@"sold_url"];
    [dict setValue:[NSString stringWithFormat:@"%@",[self.dictionary objectForKey:@"sold_title"]] forKey:@"sold_title"];
    
  
    if (self.pictureinfolist.count>0) {
        NSData * JSONData = [NSJSONSerialization dataWithJSONObject:self.pictureinfolist
                                                            options:kNilOptions
                                                              error:nil];
        NSString *jsonString = [[NSString alloc] initWithData:JSONData
                                                     encoding:NSUTF8StringEncoding];
        [dict setValue:jsonString forKey:@"pictureinfolist"];
        [dict setValue:self.top forKey:@"top"];
    }
    
    [[ZToastManager ShardInstance] showprogress];
    __weak typeof (self) wSelf = self;
    [BaseModel publishProduct:dict success:^(AFHTTPRequestOperation *operation, id result) {
        [wSelf parserResultObject:result];
        [[ZToastManager ShardInstance] hideprogress];
    } failure:^(NSError *error) {
        [[ZToastManager ShardInstance] hideprogress];
        [[ZToastManager ShardInstance] showtoast:@"请求失败"];
    }];
    
}
-(void)parserResultObject:(id)resultObject
{
    [[ZToastManager ShardInstance] hideprogress];
    if (resultObject==nil) {
        return;
    }
    if (resultObject && [resultObject isKindOfClass:[NSDictionary class]]) {
        [[ZToastManager ShardInstance] showtoast:[resultObject objectForKey:@"msg"]];
        if ([[resultObject objectForKey:@"code"] intValue]==1)
        {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"updateLoveList" object:nil];
            if (self.type==0||self.type==3) //首页
            {
                GoodViewController *good =[[GoodViewController alloc] init];
                good.type =self.type;
                good.dictionary =resultObject;
                good.photo_id = [NSString stringWithFormat:@"%@",[resultObject objectForKey:@"photo_id"]];
                [self.navigationController pushViewController:good animated:YES];
                good=nil;
            }
        }
    }
}
@end
